using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public partial class UIMapManager
    {
        private class UIQuestTargetSymbol : UINormalMapSymbol
        {
            public override bool updatable => true;

            protected override void Draw()
            {
                base.Draw();
                ui.icon.maskable = owner.curContainer is not UIN_MiniMap;
            }

            protected override void UpdateTransform()
            {
                var playerWorldPos = GameplayAreaManager.Instance.curSceneArea.GetPlayerAvatarEntity().transform.position;
                var playerPos = owner.PositionWorldToMap(playerWorldPos);
                var targetPos = owner.PositionWorldToMap(data.worldPosition);
                var distance = Vector2.Distance(playerPos, targetPos);
                transform.localPosition = playerPos + Mathf.Min(owner.curContainer.radius / owner.transform.localScale.x, distance) *
                    (targetPos - playerPos).normalized;
                var degree = Mathf.Acos(Vector2.Dot(Vector2.down, targetPos - playerPos) / distance) *
                             Mathf.Rad2Deg;
                transform.localRotation = Quaternion.Euler(0, 0, degree);
            }
        }
    }
}